package dk.dashboardFP.panels.introspectionPanel {
	import dk.dashboardFP.panels.subPanels.ui.windowSubPanelUI.IWindowContent;
	import dk.dashboardFP.panels.subPanels.ui.windowSubPanelUI.WindowContentEvent;
	import dk.dashboardFP.panels.subPanels.ui.windowSubPanelUI.scrollWindow.WindowContentScrollRequest;

	import flash.display.Sprite;
	import flash.geom.Point;

	/**
	 * @author josef
	 */
	public class IntrospectionWindowContent extends Sprite implements IWindowContent {
		private var _doRootNode : IntrospectionNodeView;
		private var _pWindowDimentions : Point;

		public function IntrospectionWindowContent() {
			setupElements();
		}

		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		// setup
		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

		private function setupElements() : void {
		}

		public function renderIntrospectionTree(rootNodeView:IntrospectionNodeView) : void {
			
			//:::::::
			// remove old 
			if (_doRootNode) {
				removeChild(_doRootNode);
			}
			
			_doRootNode = rootNodeView;
			
			//:::::::
			// setup root
			addChild(_doRootNode);
			
			_doRootNode.x=15;
			_doRootNode.y=4;
			
			_doRootNode.addEventListener(IntrospectionNodeViewEvent.HEIGHT_CHANGED, onHeightUpdated, false, 0, true);
			
			//:::::::
			// init 
			_doRootNode.setWidth(_pWindowDimentions.x-16);
			
			onHeightUpdated(null);
		}

		private function onHeightUpdated(event : IntrospectionNodeViewEvent) : void {
			dispatchEvent(new WindowContentEvent(WindowContentEvent.CONTENT_DIMENTIONS_CHANGE));
		}

		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		// build
		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		
		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		// search
		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		
		public function search(value : String) : void {
			
			var tempHeight:Number=height;
			
			_doRootNode.search(value);
			
			if (tempHeight!=height) {
				dispatchEvent(new WindowContentEvent(WindowContentEvent.CONTENT_DIMENTIONS_CHANGE, WindowContentScrollRequest.TO_TOP));
			}
		}

		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		// interface
		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		
		public function setWindowDimentions(pWindowDimentions : Point) : void {
			_pWindowDimentions = pWindowDimentions;
			if (_doRootNode) {
				_doRootNode.setWidth(pWindowDimentions.x-16);
			}
		}

		public function set nWindowWidth(nWindowWidth : Number) : void {
		}

		public function set nWindowHeight(nWindowHeight : Number) : void {
		}
	}
}
